var _v;
var vueModel = {
    el: '.main-pay',
    data: {
        orderQuery: location.search,
        room_type_id: '',
        params: {
            hotel_id: '',
            room_id: '',
            in_date: '',
            out_date: '',
            contract_member: '',
            contract_mobile: '',
            room_number: '',
            stay_persons: [],
            dis_self_sn: ''
        },
        breakfast: '',
        total_price: '',
        orderId: '',
        orderInfo: {

        },
        hotelDetail: {
            images: {
                list: [
                    {
                        imgid: ''
                    }, {
                        imgid: ''
                    }, {
                        imgid: ''
                    }, {
                        imgid: ''
                    }, {
                        imgid: ''
                    }
                ]
            },
        },
        rules: {
            dis_self_sn: [
                { required: true, message: '订单号必填！', trigger: 'blur' },
            ]
        },
        loading: false
    },
    computed: {
        roomType: function() {
            switch (parseInt(_v.room_type_id)) {
                case 1:
                    return '标准房'
                    break;
                case 2:
                    return '高级房'
                    break;
                case 3:
                    return '豪华房'
                    break;
                case 4:
                    return '商务房'
                    break;
                case 5:
                    return '行政房'
                    break;
                case 6:
                    return '双人房'
                    break;
                case 7:
                    return '单人房'
                    break;
                case 8:
                    return '豪华套房'
                    break;
            }
        }
    },
    methods: {
        paySubmit: function() {
            _v.loading = true;
            HQ.ajax('/room/order/submit', JSON.stringify({ hotel_order_id: _v.orderId }), function(res){
                _v.loading = false;
                this.$message({
                    type: 'success',
                    message: '恭喜预约成功!'
                });
                location.href="/index.html";
            }, function(){_v.loading = false;}, "POST");
        },
        getQueryVariable: function (variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        },
        fetchData: function () {
            HQ.ajax('/room/order/info', JSON.stringify({
                hotel_order_id: _v.orderId
            }), function(res){
                // {
                //     "code": 0,
                //     "msg": "操作成功",
                //     "data": {
                //     "hotel_name": "曼谷铂尔曼皇权酒店Pullman Bangkok King Power Hotel",
                //         "dist_order_sn": "2020051021481410154519",
                //         "in_date": "2020-05-12",
                //         "out_date": "2020-05-13",
                //         "stay_person": [
                //         {
                //             "person_name": "陶xx",
                //             "person_mobile": "33333333"
                //         }
                //     ],
                //         "room_type_id": 3,
                //         "room_type_name": "豪华房",
                //         "room_bed_name": "双床1.2米",
                //         "room_number": 1,
                //         "has_bread_fast": 2,
                //         "price": 110.5
                // }
                // }
                _v.orderInfo = res.data;
                _v.orderInfo.stay_person = _v.orderInfo.stay_person.slice(0, _v.orderInfo.room_number)
            }, function(){}, "POST");
        }
    },
    created: function() {
        _v = this;
    },
    mounted: function () {
        _v.params.in_date = _v.getQueryVariable('date_start') || '2020-05-06';
        _v.params.out_date = _v.getQueryVariable('date_end') || '2020-05-07';
        _v.params.room_id = _v.getQueryVariable('room_id') || '';
        _v.room_type_id = _v.getQueryVariable('room_type_id') || '';
        _v.params.room_number = _v.getQueryVariable('room_number') || '';
        _v.params.hotel_id = _v.getQueryVariable('hotel_id') || '';
        _v.orderId = _v.getQueryVariable('orderId') || '';
        _v.orderQuery = _v.orderId;
        _v.fetchData();
    }
}

$(function() {
    new Vue(vueModel);
})